﻿using System.Collections.Generic;

namespace DotNetCommon.PinYin.Internals;

internal class TrieNode
{
    public int Index;
    public int Layer;
    public bool End;
    public char Char;
    public List<int> Results;
    public Dictionary<char, TrieNode> m_values;
    public TrieNode Failure;
    public TrieNode Parent;


    public TrieNode()
    {
        m_values = new Dictionary<char, TrieNode>();
        Results = new List<int>();
    }

    public TrieNode Add(char c)
    {
        TrieNode node;
        if (m_values.TryGetValue(c, out node))
        {
            return node;
        }
        node = new TrieNode();
        node.Parent = this;
        node.Char = c;
        m_values[c] = node;
        return node;
    }

    public void SetResults(int index)
    {
        if (End == false)
        {
            End = true;
        }
        Results.Add(index);
    }

}
